To handle the Display Notice event as a high-level event like any other Apple event, you need to
isHighLevelEventAware
bit in your application's '
SIZE
' resource to indicate that your application supports high-level events (in which case your application must also support the four required Apple events)
AEInstallEventHandler
function to install the entry for handling the Display Notice event in your application's Apple event dispatch table
If you want your application to handle all window positioning itself (that is, if you do not want the Display Manager to automatically move any of your windows), you should also set the
isDisplayManagerAware
bit in the '
SIZE
' resource.
void MyDoEvent(EventRecord *event) { short part, err; WindowPtr window; char key; switch ( event->what ) { /* here, handle null, mouse down, key down, update, and other necessary events */ case kHighLevelEvent: DoHighLevelEvent(event); break; } } void DoHighLevelEvent(EventRecord *event) { OSErr myErr; /* handling only Apple-event types of high-level events */ myErr = AEProcessAppleEvent(event); }
Your application must use the
AEInstallEventHandler
function to add an entry to your application's Apple event dispatch table. This entry is the function that responds to the Display Notice event. For example, the following code fragment illustrates how to use
AEInstallEventHandler
to install an application-defined function called
DoAEDisplayUpdate
.
err = AEInstallEventHandler (kCoreEventClass, kAESystemConfigNotice, (ProcPtr)DoAEDisplayUpdate, 0, false);
Listing 3-2 shows an application-defined function called
DoAEDisplayUpdate
that uses Apple Event Manager functions to obtain information about the various video devices reported by the Display Notice event. The function
DoAEDisplayUpdate
uses this information to update its internal data structures for its windows and then calls another application-defined function that ensures that its windows are displayed optimally in the new configuration environment.
pascal OSErr DoAEDisplayUpdate (AppleEvent theAE,AppleEvent reply,long ref) { #pragma unused(theAE,reply,ref) AEDescList DisplayList; AEDescList DisplayID; AERecord OldConfig,NewConfig; AEKeyword tempWord; AEDesc returnType; OSErr myErr; long result; long count; Rect oldRect, newRect; Size actualSizeUnused; /* get a list of the displays from the Display Notice event */ myErr = AEGetParamDesc(&theAE,kAEDisplayNotice,typeWildCard,&DisplayList); /* count the elements in the list */ myErr = AECountItems(&DisplayList,&count); while (count >0) /* decode the Display Notice event */ { myErr = AEGetNthDesc(&DisplayList, count, typeWildCard, &tempWord, &DisplayID); myErr = AEGetNthDesc(&DisplayID, 1, typeWildCard, &tempWord, &OldConfig); myErr = AEGetKeyPtr(&OldConfig, keyDeviceRect, typeWildCard, &returnType, &oldRect, 8, actualSizeUnused); myErr = AEGetNthDesc(&DisplayID, 2, typeWildCard, &tempWord, &NewConfig); myErr = AEGetKeyPtr(&NewConfig, keyDeviceRect, typeWildCard, &returnType, &newRect, 8, actualSizeUnused); /* update internal info about the gdRects for the devices */ MyUpdateWindowStructures(oldRect, newRect); count--; } /* move and resize windows as necessary*/ MyDisplayWindows(); return (noErr); }